package com.wdl.fmnew.core.base;

import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;


import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import dagger.android.AndroidInjection;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.support.HasSupportFragmentInjector;

/**
 * Created by wdl on 2017/9/16.
 * 仿照rxlifecycle2的rxactivity实现自己的基类
 */

public abstract class BaseActivity extends AppCompatActivity implements HasSupportFragmentInjector {

    private Unbinder bind;

    @Inject
    DispatchingAndroidInjector<Fragment> supportFragmentInjector;

    protected abstract int getContentView();

    protected abstract void loadView();

    @Override
    @CallSuper
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        AndroidInjection.inject(this);
        super.onCreate(savedInstanceState);
        setContentView(getContentView());
        bind = ButterKnife.bind(this);
        loadView();
    }


    @Override
    @CallSuper
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }


    @Override
    public AndroidInjector<Fragment> supportFragmentInjector() {
        return supportFragmentInjector;
    }
}
